<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 300px;
            margin:100px auto;
            /* box-shadow: 0 2px 0 2px rgb(0, 0, 0, 20%); */
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        let box = document.querySelector('.box');
        time()

        function time() {
            let timer = new Date();
            let year = timer.getFullYear();
            let Month = timer.getMonth() + 1;
            let month = Month < 10 ? '0' + Month : Month
            let date = timer.getDate();
            let dates = date < 10 ? '0' + date : date
            let day = timer.getDay();
            let Hours = timer.getHours();
            let hours = Hours < 10 ? '0' + Hours : Hours
            let Minutes = timer.getMinutes();
            let minutes = Minutes < 10 ? '0' + Minutes : Minutes
            let Seconds = timer.getSeconds();
            let second = Seconds < 10 ? '0' + Seconds : Seconds
            // console.log(year,Month,date,day,hours,Minutes,Seconds);
            // box.innerHTML = '今天是' + year + '年' + month + '月' + dates + '日' + '星期' + day + '\n' + hours + '时' + Minutes + '分' + Seconds + '秒';
            box.innerHTML = '现在是' + hours + '时' + minutes + '分' + second + '秒';
            let h = parseFloat(Hours / 60 / 60 / 24);
        }
        setInterval(time , 100)
        // d = parseInt(总秒数/60/60/24)
        // h = parseInt(总秒数/60/60%24)
        // m = parseInt(总秒数/60%60)
        // s = parseInt(总秒数%60)
        //获取zo
        function countDown(time){
            let nowTime = +new Date();
            // let now = time;
            let future =  +new Date(time);
            let times = (nowTime - future)/1000
            let d = parseInt(times/60/60/24)
            let h = parseInt(times/60/60%24)
            let m = parseInt(times/60%60)
            let s = parseInt(times%60);
            return d + '天' + h + '时' + m + '分' + s + '秒'
        }
        document.write(countDown('2021-4-7 13:00:00'))
        // setInterval(countDown('2021-4-7 11:00:00'));
    </script>
</body>

</html>